import 'package:eh_mobile/common/store/index.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../routers/route_names.dart';
import '../store/config_store.dart';

/// 第一次欢迎页面
class RouteWelcomeMiddleware extends GetMiddleware {
  // priority 数字小优先级高
  @override
  // ignore: overridden_fields
  int? priority = 0;

  RouteWelcomeMiddleware({required this.priority});

  @override
  RouteSettings? redirect(String? route) {
    if (ConfigStore().isFirstOpen == true) {
      return const RouteSettings(name: RouteNames.mainHomepage);
    } else if (UserStore().isLogin == true) {
      return const RouteSettings(name: RouteNames.mainHomepage);
    } else {
      return const RouteSettings(name: RouteNames.LOGIN);
   }
  }
}
